<?php

namespace App\Containers\AppSection\User\Tasks;

use App\Containers\AppSection\User\Data\Repositories\UserRepository;
use App\Ship\Criterias\Where;
use App\Ship\Exceptions\NotFoundException;
use App\Ship\Parents\Tasks\Task;

class CheckUserIsBannedTask extends Task
{
    protected UserRepository $repository;

    public function __construct(UserRepository $repository)
    {
        $this->repository = $repository;
    }

    public function run($id): bool
    {
        try {
            return !!$this->repository
                ->pushCriteria(new Where('ban_id', '=', null))
                ->find($id);
        } catch (Exception $exception) {
            throw new NotFoundException(__('ship::resource.not-found'));
        }

    }
}
